<template>
    <view class="container">
      <!-- 收藏列表 -->
      <scroll-view class="list-scroll" scroll-y>
        <view 
            v-for="(item, index) in newsList" 
            :key="index"
            class="info-card"
        >
            <view 
            class="info-content"
            @click="goToDetail(item.collectionId, item.collectionType)"
            >
            <text class="info-title">{{ item.title }}</text>
            <text class="info-date">{{ item.createTime }}</text>
            </view>
            <view class="delete-btn" @click.stop="deleteItem(item.id,index)">
            <text>删除</text>
            </view>
        </view>
    </scroll-view>
    </view>
  </template>
  
  <script>
  import { getCollectionList,delCollection } from '@/api/collection'
  export default {
    data() {
      return {
        newsList: [
          // 原始数据保持不动
          
        ]
      }
    },
    async created() {
      
      try {
        // 获取全部收藏列表
        let param = {
          pageNum:1,
          count:20
        }
        const res = await getCollectionList(param)
        // console.log("res===",res);
        if(res){
          this.newsList = res.list;
  
        }
      } catch (error) {
        console.error('获取收藏列表失败', error)
      }
    },
    methods: {
        deleteItem(id, index) {
            // 调用删除接口
            delCollection(id).then(() => {
            // 删除成功后从列表中移除
            this.newsList.splice(index, 1)
            }).catch(error => {
            console.error('删除失败:', error)
            })
        },
      goToDetail(id,type) {
        uni.navigateTo({
          url: `/pages/product/detail?id=${id}`
        })
      }
    },
    onLoad(options) {
      // console.log("options===", options.type)
  
      this.activeType = decodeURIComponent(options.type || '企业概况')
    },
    onShow() {
      // 监听参数更新
      uni.$on('updateInfoType', (type) => {
        // console.log('更新参数：', type)
        this.activeType = type
        this.activeNav = this.navItems.indexOf(type)
      })
    },
    onUnload() {
      uni.$off('updateInfoType')
    }
  }
  </script>
  
  <style>
.container {
  padding: 15px;
  background: #f5f5f5;
}

.list-scroll {
  margin-top: 10px; /* 调整顶部间距 */
  height: calc(100vh - 100px);
}

.info-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 8px; /* 增加卡片间距 */
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.info-content {
  flex: 1;
  margin-right: 16px; /* 增加内容与按钮间距 */
}

.info-title {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
}

.info-date {
  font-size: 12px;
  color: #999;
}

.delete-btn {
  padding: 6px 12px;
  background-color: #ff4d4f;
  color: white;
  border-radius: 16px; /* 改为圆角 */
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.delete-btn:hover {
  background-color: #ff7875; /* 添加hover效果 */
  transform: scale(1.05);
}

.delete-btn:active {
  transform: scale(0.95);
}
</style>